import time
from selenium.webdriver.common.by import By
from common.Utils import BlogDriver

class BlogList:
    driver = ""
    url = ""
    def __init__(self):
        self.driver = BlogDriver.driver
        self.url = "http://8.137.19.140:9090/blog_list.html"
        self.driver.get(self.url)

    def BlogLoginListTest(self):#登录状态下
        # 检查一下博客的标题是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > div.title")
        # 发布博客的时间是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > div.date")
        # 博客的内容是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > div.desc")
        # 博客列表页的查看全文按钮是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > a")
        # 用户基本信息的昵称是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > h3")
        # 用户基本信息的文章是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)")
        # 用户基本信息的分类是否存在
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(4) > span:nth-child(2)")
        # 检查一下博客数量是否为0，不为就就通过
        Blognum = self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)").text
        print(Blognum)
        assert Blognum != 0
        BlogDriver.GetScreenShot()
        # self.driver.quit()

    def NotBlogLoginListTest(self):#未登录状态下
        # 找到用户命名输入框和密码输入框把里面的内容清空
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.get("http://8.137.19.140:9090/blog_list.html")

        time.sleep(2)
        BlogDriver.GetScreenShot()
        self.driver.find_element(By.CSS_SELECTOR, "body > div.container > div.right > div:nth-child(1) > div.title")
